import * as types from "../action-types";
import {put, take,takeEvery,call,cps} from '../../redux-saga/effects';
// import {delay} from '../utils';



const  delay =(ms,callback) => {
    setTimeout(() => {
        callback(ms)
    },ms)
}

function* increment() {
    // debugger
    // const res = yield call(delay,1000);
    const res = yield cps(delay,1000);
    // const res = yield delay(1000);
    console.log('res',res);
    yield put({type: types.INCREMENT})
}


function* first() {
    for (let i = 0; i < 3; i++) {
        //take  监听一次ASYNC_INCREMENT动作  （take每次循环只监听一次，）
        const action = yield  take(types.ASYNC_INCREMENT)
        console.log(action)
        yield  increment();   //开源直接yield一个iterator
    }
    alert('最多执行三次')
}

export default function* () {
    yield takeEvery(types.ASYNC_INCREMENT,increment);
   console.log('countsaga执行完了')
}


